package com.cy.pj.sys.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.util.PageUtil;
import com.cy.pj.sys.pojo.SysStudent;
import com.cy.pj.sys.service.SysStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student/")
public class SysStudentController {
    @Autowired
    private SysStudentService sysStudentService;

    @GetMapping
    public JsonResult findStudent(SysStudent sysStudent){
        return new JsonResult(PageUtil.startPage().doSelectPageInfo(()->{
            sysStudentService.findStudent(sysStudent);
      //  return new JsonResult( sysStudentService.findStudent(sysStudent));

        }));
    }

    @GetMapping("{id}")
    public JsonResult selectById(@PathVariable Long id){
        return new JsonResult(sysStudentService.selectById(id));
    }

    @PostMapping
    public JsonResult insertStu(@RequestBody SysStudent sysStudent){
        return new JsonResult(sysStudentService.insertStu(sysStudent));
    }

    @DeleteMapping("{id}")
    public  JsonResult deleteById(@PathVariable Long id){
        return new JsonResult(sysStudentService.deleteById(id));
    }

    @PutMapping
    public JsonResult updateStu(@RequestBody SysStudent sysStudent){
        return new JsonResult(sysStudentService.updateStu(sysStudent));
    }
}
